{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "view-in-github"
   },
   "source": [
    "<a href=\"https://colab.research.google.com/github/vitaldb/examples/blob/master/asa_mortality.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Comparison of mortality rates depending on ASA physical status class\n",
    "In this example, we will learn how to estimate and compare mortality rates depending on ASA physical status class with <code>VitalDB</code> dataset.<br>\n",
    "\n",
    "> Note that <b>all users who use Vital DB, an open biosignal dataset, must agree to the Data Use Agreement below. </b> If you do not agree, please close this window. Click here: [Data Use Agreement](https://vitaldb.net/dataset/?query=overview&documentId=13qqajnNZzkN7NZ9aXnaQ-47NWy7kx-a6gbrcEsi-gak&sectionId=h.vcpgs1yemdb5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Preparation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 916
    },
    "id": "bwuP-YwMcLgo",
    "outputId": "865d6a7b-dd53-486d-9526-886a157b263f"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.8922980588603632\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>caseid</th>\n",
       "      <th>subjectid</th>\n",
       "      <th>casestart</th>\n",
       "      <th>caseend</th>\n",
       "      <th>anestart</th>\n",
       "      <th>aneend</th>\n",
       "      <th>opstart</th>\n",
       "      <th>opend</th>\n",
       "      <th>adm</th>\n",
       "      <th>dis</th>\n",
       "      <th>...</th>\n",
       "      <th>intraop_colloid</th>\n",
       "      <th>intraop_ppf</th>\n",
       "      <th>intraop_mdz</th>\n",
       "      <th>intraop_ftn</th>\n",
       "      <th>intraop_rocu</th>\n",
       "      <th>intraop_vecu</th>\n",
       "      <th>intraop_eph</th>\n",
       "      <th>intraop_phe</th>\n",
       "      <th>intraop_epi</th>\n",
       "      <th>intraop_ca</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>5955</td>\n",
       "      <td>0</td>\n",
       "      <td>11542</td>\n",
       "      <td>-552</td>\n",
       "      <td>10848.0</td>\n",
       "      <td>1668</td>\n",
       "      <td>10368</td>\n",
       "      <td>-236220</td>\n",
       "      <td>627780</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>120</td>\n",
       "      <td>0.0</td>\n",
       "      <td>100</td>\n",
       "      <td>70</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>2487</td>\n",
       "      <td>0</td>\n",
       "      <td>15741</td>\n",
       "      <td>-1039</td>\n",
       "      <td>14921.0</td>\n",
       "      <td>1721</td>\n",
       "      <td>14621</td>\n",
       "      <td>-221160</td>\n",
       "      <td>1506840</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>150</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>100</td>\n",
       "      <td>0</td>\n",
       "      <td>20</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>2861</td>\n",
       "      <td>0</td>\n",
       "      <td>4394</td>\n",
       "      <td>-590</td>\n",
       "      <td>4210.0</td>\n",
       "      <td>1090</td>\n",
       "      <td>3010</td>\n",
       "      <td>-218640</td>\n",
       "      <td>40560</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>50</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>1903</td>\n",
       "      <td>0</td>\n",
       "      <td>20990</td>\n",
       "      <td>-778</td>\n",
       "      <td>20222.0</td>\n",
       "      <td>2522</td>\n",
       "      <td>17822</td>\n",
       "      <td>-201120</td>\n",
       "      <td>576480</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>80</td>\n",
       "      <td>0.0</td>\n",
       "      <td>100</td>\n",
       "      <td>100</td>\n",
       "      <td>0</td>\n",
       "      <td>50</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>4416</td>\n",
       "      <td>0</td>\n",
       "      <td>21531</td>\n",
       "      <td>-1009</td>\n",
       "      <td>22391.0</td>\n",
       "      <td>2591</td>\n",
       "      <td>20291</td>\n",
       "      <td>-67560</td>\n",
       "      <td>3734040</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>160</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>900</td>\n",
       "      <td>0</td>\n",
       "      <td>2100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6383</th>\n",
       "      <td>6384</td>\n",
       "      <td>5583</td>\n",
       "      <td>0</td>\n",
       "      <td>15248</td>\n",
       "      <td>-260</td>\n",
       "      <td>15640.0</td>\n",
       "      <td>2140</td>\n",
       "      <td>14140</td>\n",
       "      <td>-215340</td>\n",
       "      <td>648660</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>150</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>90</td>\n",
       "      <td>0</td>\n",
       "      <td>20</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6384</th>\n",
       "      <td>6385</td>\n",
       "      <td>2278</td>\n",
       "      <td>0</td>\n",
       "      <td>20643</td>\n",
       "      <td>-544</td>\n",
       "      <td>20996.0</td>\n",
       "      <td>2396</td>\n",
       "      <td>19496</td>\n",
       "      <td>-225600</td>\n",
       "      <td>1675200</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>100</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>100</td>\n",
       "      <td>0</td>\n",
       "      <td>25</td>\n",
       "      <td>30</td>\n",
       "      <td>0</td>\n",
       "      <td>300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6385</th>\n",
       "      <td>6386</td>\n",
       "      <td>4045</td>\n",
       "      <td>0</td>\n",
       "      <td>19451</td>\n",
       "      <td>-667</td>\n",
       "      <td>19133.0</td>\n",
       "      <td>3533</td>\n",
       "      <td>18233</td>\n",
       "      <td>-200460</td>\n",
       "      <td>836340</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>70</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>130</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6386</th>\n",
       "      <td>6387</td>\n",
       "      <td>5230</td>\n",
       "      <td>0</td>\n",
       "      <td>12025</td>\n",
       "      <td>-550</td>\n",
       "      <td>12830.0</td>\n",
       "      <td>1730</td>\n",
       "      <td>11030</td>\n",
       "      <td>-227760</td>\n",
       "      <td>377040</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>120</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>50</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6387</th>\n",
       "      <td>6388</td>\n",
       "      <td>1306</td>\n",
       "      <td>0</td>\n",
       "      <td>10249</td>\n",
       "      <td>-79</td>\n",
       "      <td>10121.0</td>\n",
       "      <td>2321</td>\n",
       "      <td>9221</td>\n",
       "      <td>-312060</td>\n",
       "      <td>379140</td>\n",
       "      <td>...</td>\n",
       "      <td>500</td>\n",
       "      <td>120</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>90</td>\n",
       "      <td>0</td>\n",
       "      <td>20</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>6388 rows × 74 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      caseid  subjectid  casestart  caseend  anestart   aneend  opstart  \\\n",
       "0          1       5955          0    11542      -552  10848.0     1668   \n",
       "1          2       2487          0    15741     -1039  14921.0     1721   \n",
       "2          3       2861          0     4394      -590   4210.0     1090   \n",
       "3          4       1903          0    20990      -778  20222.0     2522   \n",
       "4          5       4416          0    21531     -1009  22391.0     2591   \n",
       "...      ...        ...        ...      ...       ...      ...      ...   \n",
       "6383    6384       5583          0    15248      -260  15640.0     2140   \n",
       "6384    6385       2278          0    20643      -544  20996.0     2396   \n",
       "6385    6386       4045          0    19451      -667  19133.0     3533   \n",
       "6386    6387       5230          0    12025      -550  12830.0     1730   \n",
       "6387    6388       1306          0    10249       -79  10121.0     2321   \n",
       "\n",
       "      opend     adm      dis  ...  intraop_colloid  intraop_ppf  intraop_mdz  \\\n",
       "0     10368 -236220   627780  ...                0          120          0.0   \n",
       "1     14621 -221160  1506840  ...                0          150          0.0   \n",
       "2      3010 -218640    40560  ...                0            0          0.0   \n",
       "3     17822 -201120   576480  ...                0           80          0.0   \n",
       "4     20291  -67560  3734040  ...                0            0          0.0   \n",
       "...     ...     ...      ...  ...              ...          ...          ...   \n",
       "6383  14140 -215340   648660  ...                0          150          0.0   \n",
       "6384  19496 -225600  1675200  ...                0          100          0.0   \n",
       "6385  18233 -200460   836340  ...                0           70          0.0   \n",
       "6386  11030 -227760   377040  ...                0          120          0.0   \n",
       "6387   9221 -312060   379140  ...              500          120          0.0   \n",
       "\n",
       "     intraop_ftn  intraop_rocu  intraop_vecu  intraop_eph  intraop_phe  \\\n",
       "0            100            70             0           10            0   \n",
       "1              0           100             0           20            0   \n",
       "2              0            50             0            0            0   \n",
       "3            100           100             0           50            0   \n",
       "4              0           160             0           10          900   \n",
       "...          ...           ...           ...          ...          ...   \n",
       "6383           0            90             0           20            0   \n",
       "6384           0           100             0           25           30   \n",
       "6385           0           130             0           10            0   \n",
       "6386           0            50             0            0            0   \n",
       "6387           0            90             0           20            0   \n",
       "\n",
       "      intraop_epi intraop_ca  \n",
       "0               0          0  \n",
       "1               0          0  \n",
       "2               0          0  \n",
       "3               0          0  \n",
       "4               0       2100  \n",
       "...           ...        ...  \n",
       "6383            0          0  \n",
       "6384            0        300  \n",
       "6385            0          0  \n",
       "6386            0          0  \n",
       "6387            0          0  \n",
       "\n",
       "[6388 rows x 74 columns]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "# Load clinical information data\n",
    "df_cases = pd.read_csv(\"https://api.vitaldb.net/cases\")\n",
    "\n",
    "# Print the average of death in hospital\n",
    "print(df_cases.death_inhosp.mean() * 100)\n",
    "\n",
    "df_cases"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Data Visualization"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 319
    },
    "id": "JcPTJzW6cgM8",
    "outputId": "3f820f95-fb5b-4c57-8b91-c38b58bc5c4d"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.5451241671714113, 0.2991325157044571, 1.3671875, 18.181818181818183]\n",
      "[0.0, 1.9662921348314606, 5.2356020942408374, 27.027027027027028]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<module 'matplotlib.pyplot' from 'C:\\\\Users\\\\admin\\\\Anaconda3\\\\lib\\\\site-packages\\\\matplotlib\\\\pyplot.py'>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAD4CAYAAADrRI2NAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAWBklEQVR4nO3dfbBU9Z3n8fcXgrmoiFFJxg3iJa7GhyCIV1c0umpGYIhe4yiFTmLUjUsiGh/WqllwaxONVJYyDLOZ1GYcMoLu+MQmatRxkkF8LI1BQK9GRYNmyQSlRCUiV0VFv/tHNyzhoblAn277nverquv2+fW55/ftU8XnHn7nnN+JzESSVB59ml2AJKmxDH5JKhmDX5JKxuCXpJIx+CWpZD7R7AJ6Yq+99sr29vZmlyFJLWXRokWvZ+agjdtbIvjb29tZuHBhs8uQpJYSEb/fXLtDPZJUMga/JJWMwS9JJdMSY/yb88EHH7Bs2TLWrFnT7FJ6vba2NgYPHky/fv2aXYqkOmjZ4F+2bBkDBgygvb2diGh2Ob1WZvLGG2+wbNkyhg4d2uxyJNVByw71rFmzhj333NPQL1hEsOeee/o/K6kXadngBwz9BnE/S71LSwe/JGnbtewY/8baJ99T1+0tnfblra7Tt29fhg0btn75zDPPZPLkyRx//PFMnz6djo6Obeqzq6uLV155hXHjxgFw11138dxzzzF58uRtK16Saug1wd8M/fv3p6urq27b6+rqYuHCheuDv7Ozk87OzrptX9IOunJgE/pcVfdNOtRTsLlz5zJq1ChGjhzJ+PHj6e7uBmDBggUcffTRDB8+nCOPPJJVq1bxne98hzlz5jBixAjmzJnD9ddfz0UXXcSqVatob2/no48+AuCdd95hn3324YMPPuCll15i7NixHH744Rx77LE8//zzzfy6klqAwb8D3n33XUaMGLH+NWfOnD/5/PXXX2fq1KnMmzePJ554go6ODmbMmMH777/PhAkT+OEPf8hTTz3FvHnz2GWXXfje977HhAkT6OrqYsKECeu3M3DgQIYPH85DDz0EwN13382YMWPo168fEydO5Ec/+hGLFi1i+vTpTJo0qaH7QFLrcahnB2xtqOfXv/41zz33HMcccwwA77//PqNGjeKFF15g77335ogjjgBgt91222pfEyZMYM6cOZxwwgnceuutTJo0ie7ubn71q18xfvz49eu99957O/alJPV6Bn+BMpOTTjqJW2655U/an3766W2+R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xxxhn84he/4Oc//znz589n5513ZuXKleyxxx4MHDiQrq4uRowYwezZszn33HMbvSslNVBhwR+V6SevAxZn5owN2veujv8DnAY8U1QNRas11LPuyVnDhg2ju7ubAQMGMGDAANra2njzzTeZO3cuc+fO5bDDDgOgu7ubJUuWMGTIEPbdd1+OOuooAB555BFOPfVU+vfvD8App5yyfv1aUzJ/5StfoU+fPhx88MG8+mrlb+28efM477zz2HnnnQHYY489ADj//POZPXs2M2bMYM6cOTz++OP12kWSPoaKPOI/Bjgb+E1EdFXbrgDOiogRQAJLgW8WWEPTfPKTnwSgT58+69+vW167di2ZyZQpU/jmN//06y9dupRddtll/fKW5lL66KOPak7JvGGf67aRmZudDvr000/nqquu4sQTT+Twww9nzz337NmXlNSSChvjz8xHMjMy89DMHFF9/Utmnp2Zw6rtnRsc/ZfKmDFjmDVr1vpHMb788susWLFik/W++MUvcvfdd7NmzRq6u7u5557KQ+W3Z0rm0aNHM2vWLN555x0AVq5cCUBbWxtjxozhggsu4Lzzzqvbd5T08dRrpmUu4oHEW7O1aZlrGT16NIsXL2bUqFFAZb79G2+8kb59+/7JekcccQSdnZ0MHz6cfffdl46ODgYOrFy6uq1TMo8dO5auri46OjrYaaedGDduHN///vcB+OpXv8rtt9/O6NGjt2UXSGpBTsvcArq7u9l111155513OO6445g5c+afXIlTD9OnT2fVqlVcffXVm/28TPtb2qJeMi1z7zni78UmTpzIc889x5o1azjnnHPqHvqnnXYaL7300vorgiT1bgZ/C7j55psL3f4dd9xR6PYlfby09C2hrTBM1Ru4n6XepWWDv62tjTfeeMNQKlhm8sYbb9DW1tbsUiTVScsO9QwePJhly5bx2muvNbuUXq+trY3Bgwc3uwxJddKywd+vXz+GDh3a7DIkqeW07FCPJGn7GPySVDIGvySVjMEvSSVj8EtSyRj8klQyBr8klYzBL0klY/BLUskY/JJUMga/JJWMwS9JJWPwS1LJGPySVDIGvySVjMEvSSVj8EtSyRj8klQyBr8klYzBL0klY/BLUskUFvwRsU9EPBARiyPi2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QyBr8klYzBL0klY/BLUskY/JJUMr3+cs5GXzoHsHTalxvepyT1VFOO+CNibES8EBEvRsTkZtQgSWXV8CP+iOgL/C/gJGAZsCAi7srM5xpdi3quKf9z8sYjqRDNOOI/EngxM3+Xme8DtwKnNqEOSSqlyMzGdhhxBjA2M8+vLp8N/IfMvGij9SYCE6uLnwdeaGihO2Yv4PVmF9ELuB/rw/1YP622L/fNzEEbNzbj5G5spm2Tvz6ZOROYWXw59RcRCzOzo9l1tDr3Y324H+unt+zLZgz1LAP22WB5MPBKE+qQpFJqRvAvAPaPiKERsRNwJnBXE+qQpFJq+FBPZq6NiIuAfwX6ArMy89lG11Gwlhyi+hhyP9aH+7F+esW+bPjJXUlSczllgySVjMEvSSVj8NdRRMyKiBUR8Uyza2llEbFPRDwQEYsj4tmIuKTZNbWiiGiLiMcj4qnqfryq2TW1sojoGxFPRsQ/N7uWHWXw19f1wNhmF9ELrAUuz8yDgKOACyPi4CbX1IreA07MzOHACGBsRBzV3JJa2iXA4mYXUQ8Gfx1l5sPAymbX0eoyc3lmPlF9v5rKP7bPNreq1pMV3dXFftWXV3Nsh4gYDHwZ+Mdm11IPBr8+1iKiHTgMmN/kUlpSdXiiC1gB3JuZ7sft8z+BvwY+anIddWHw62MrInYFbgMuzcy3ml1PK8rMDzNzBJU75I+MiC80uaSWExEnAysyc1Gza6kXg18fSxHRj0ro35SZtze7nlaXmW8CD+I5qO1xDNAZEUupzCZ8YkTc2NySdozBr4+diAjgOmBxZs5odj2tKiIGRcTu1ff9gT8Hnm9qUS0oM6dk5uDMbKcyxcz9mfm1Jpe1Qwz+OoqIW4DHgM9HxLKI+Eaza2pRxwBnUzmy6qq+xjW7qBa0N/BARDxNZY6sezOz5S9F1I5zygZJKhmP+CWpZAx+SSoZg1+SSsbgl6SSMfglqWQMfkkqGYNfkkrm/wGv9mHqY2oX4QAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "##########################################################\n",
    "# column name'asa' stands for ASA class\n",
    "# column name'emop' stands for emergency surgery\n",
    "# column name 'death_inhosp' stands for death in hospital\n",
    "##########################################################\n",
    "\n",
    "# Estimate patients' mortality rate depending on ASA class in emergency surgery\n",
    "el_y = [df_cases[(df_cases['asa'] == asa) & ~df_cases['emop']]['death_inhosp'].mean() * 100 for asa in range(1,5)]\n",
    "print(el_y)\n",
    "\n",
    "# Estimate patients' mortality rate depending on ASA class in general surgery\n",
    "em_y = [df_cases[(df_cases['asa'] == asa) & df_cases['emop']]['death_inhosp'].mean() * 100 for asa in range(1,5)]\n",
    "print(em_y)\n",
    "\n",
    "# Draw a bar graph\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "fig, ax = plt.subplots()\n",
    "w = 0.35\n",
    "x = np.arange(1,5)\n",
    "ax.bar(x - w/2, el_y, w, label='Elective')\n",
    "ax.bar(x + w/2, em_y, w, label='Emergency')\n",
    "ax.set_ylabel('Mortality (%)')\n",
    "ax.set_xticks(x)\n",
    "ax.legend()\n",
    "plt"
   ]
  }
 ],
 "metadata": {
  "colab": {
   "authorship_tag": "ABX9TyM+0SIx/0FGU/qJLw3YZX8l",
   "include_colab_link": true,
   "name": "asa_mortality.ipynb",
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
